unit bargraph;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, base, StdCtrls, Buttons, ExtCtrls, TeEngine, Series, TeeProcs,
  Chart, ComCtrls, RzButton;

type
  TfrmBarGraph = class(Tbasefrm)
    QcChat: TChart;
    Series1: TBarSeries;
    strdtpicker: TDateTimePicker;
    enddtpicker: TDateTimePicker;
    Label2: TLabel;
    Label1: TLabel;
    RzBitBtn1: TRzBitBtn;
    procedure FormCreate(Sender: TObject);
    procedure RzBitBtn1Click(Sender: TObject);
    procedure QcChatMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure strdtpickerChange(Sender: TObject);
    procedure enddtpickerChange(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmBarGraph: TfrmBarGraph;

implementation

uses dbmodule, includefile;

{$R *.dfm}

procedure TfrmBarGraph.FormCreate(Sender: TObject);
begin
  inherited;
  strdtpicker.Format:=DateFrtStr;
  enddtpicker.Format:=DateFrtStr;
  strdtpicker.Date:=now;
  enddtpicker.Date:=now;
end;

procedure TfrmBarGraph.RzBitBtn1Click(Sender: TObject);
begin
  inherited;
  QcChat.Refresh;
  with dbmodulefrm.dbtmpqryEx do begin
    active:=False;
    sql.clear;
    //sql.Add('SELECT RECORD.DATETIME As TIM, RECORD.NW As NW, RECORD.TRAYS As Tray, EMPLOYEE.NAME As [Name] FROM RECORD,EMPLOYEE');
    //SQL.Add('WHERE RECORD.RFID=EMPLOYEE.RFID');
    //SQL.Add(Format('AND RECORD.DATETIME>=#%s#',[FormatDateTime('YYYY-MM-DD',dttim)]));
    //SQL.Add(Format('AND RECORD.DATETIME<#%s#',[FormatDateTime('YYYY-MM-DD',dttim+1)]));
    //sql.Add(Format('AND Right(RECORD.RFID,%d)=''%s''',[RFIDLEN,rfid]));
    //Sql.Add('Order By RECORD.DATETIME');
    SQL.Add(Format('SELECT RIGHT(RFID,%d) As URFID, SUM(TRAYS) As Tray FROM RECORD',[RFIDLEN]));
    SQL.Add(Format('WHERE DATETIME>=#%s# AND DATETIME<#%s#',[FormatDateTime('YYYY-MM-DD',strdtpicker.Date),
                                                             FormatDateTime('YYYY-MM-DD',enddtpicker.Date)]));
    SQL.Add(Format('Group by RIGHT(RFID,%d)',[RFIDLEN]));
    SQL.Add(Format('Order by RIGHT(RFID,%d)',[RFIDLEN]));
    execsql;
    active:=True;
    //pickername:=FieldByName('Name').AsString;
    first;
    while not eof do begin
      //tmpTrays:= tmpTrays+FieldByName('Tray').AsFloat;
      //tmpWeight:=tmpWeight+FieldByName('NW').AsFloat;
      //weight.AddXY(FieldByName('TIM').AsDateTime,tmpWeight);
      //Trays.AddXY(FieldByName('TIM').AsDateTime,tmpTrays);
      Series1.Add(FieldByName('Tray').AsFloat,FieldByName('URFID').AsString);
      next;
    end;
    Active:=False;
  end;
end;

procedure TfrmBarGraph.QcChatMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  inherited;
  {Case Button of
    mbLeft: Qcchat.Page:=Qcchat.Page+1;
    else Qcchat.Page:=Qcchat.Page-1;
  end; }
end;

procedure TfrmBarGraph.strdtpickerChange(Sender: TObject);
begin
  if strdtpicker.DateTime>enddtpicker.DateTime then
    enddtpicker.DateTime:=strdtpicker.DateTime;
end;

procedure TfrmBarGraph.enddtpickerChange(Sender: TObject);
begin
  if strdtpicker.DateTime>enddtpicker.DateTime then
    strdtpicker.DateTime:=enddtpicker.DateTime;
end;

end.
